package com.example.ailiyuncloud.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.ailiyuncloud.dto.CommoditySkuByStagesDTO;
import com.example.ailiyuncloud.pojo.Result;
import com.example.ailiyuncloud.service.CommodityByStagesService;
import com.example.ailiyuncloud.vo.AddCommodityByStagesVO;
import com.example.ailiyuncloud.vo.QueryCommodityByStagesVO;
import com.example.ailiyuncloud.vo.QueryCommodityOrderVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.web.PageableDefault;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @Author: lqj
 * @Date: 2024-06-14 16:00:32
 * @Description:
 */
@Slf4j
@RestController
@RequestMapping("/byStages")
public class CommodityByStagesController {

    @Autowired
    private CommodityByStagesService commodityByStagesService;


    @PostMapping("/add")
    public Result<String> addCommodityByStagesController(@RequestBody List<AddCommodityByStagesVO> addCommodityByStagesVOList) {
        try {
            commodityByStagesService.addCommodityByStagesService(addCommodityByStagesVOList);
            return Result.OK();
        } catch (Exception e) {
            log.error("添加商品分期失败:" + e.getMessage());
            return Result.error("添加商品分期失败", e.getMessage().toString());
        }

    }


    @PostMapping("/query")
    public Result<IPage<CommoditySkuByStagesDTO>> queryCommodityByStagesController(@PageableDefault Page page,
                                                                              @RequestBody QueryCommodityByStagesVO queryCommodityByStagesVO) {
        return Result.OK(commodityByStagesService.queryCommodityByStagesService(page, queryCommodityByStagesVO));
    }


}
